﻿// -------------------------------------------------------------------------
//    @FileName         :    NFSnsDetailPart.h
//    @Author           :    gaoyi
//    @Date             :    2025-03-31
//    @Email			:    445267987@qq.com
//    @Module           :    NFSnsDetailPart
//
// -------------------------------------------------------------------------

#pragma once

#include <NFComm/NFObjCommon/NFObjPtr.h>
#include <NFLogicCommon/NFLogicShmTypeDefines.h>

#include "NFComm/NFObjCommon/NFObject.h"
#include "NFComm/NFObjCommon/NFSeqOP.h"
#include "NFLogicCommon/NFLogicBindRpcService.h"

namespace proto_ff
{
    class tbSnsRoleDetail;
}

class NFSnsRoleDetail;

class NFSnsDetailPart : public NF_OBJECT_TEMPLATE_MACRO(NFSnsDetailPart, EOT_SNS_DETAIL_PART_ID, NFObject, public NFSeqOP)
public:
    NFSnsDetailPart();

    ~NFSnsDetailPart() override;

    int CreateInit();

    int ResumeInit();

public:
    //******************part调用接口******************
    /**
     * @brief 初始化part
     * @param pMaster
     * @param partType
     * @return
     */
    virtual int Init(NFSnsRoleDetail* pMaster, uint32_t partType);

    /**
     * @brief 释放part资源
     * @return
     */
    virtual int UnInit();

    /**
     * @brief 所有部件初始化完成
     * @return
     */
    virtual int OnInit() { return 0; }

public:
    /**
     * @brief 从数据库中加载数据
     * @param pDbData
     * @return
     */
    virtual int LoadFromDb(const proto_ff::tbSnsRoleDetail* pDbData) { return 0; }

    /**
     * @brief 存储DB部件入口
     * @param pDbData
     * @return
     */
    virtual int SaveDb(proto_ff::tbSnsRoleDetail* pDbData) { return 0; }

    /**
     * @brief 注册后的初始化
     * @return
     */
    virtual int OnRegister() { return 0; }

    /**
     * @brief 登陆入口
     * @return
     */
    virtual int OnLogin() { return 0; }

    /**
     * @brief 登出入口
     * @return
     */
    virtual int OnLogout() { return 0; }

    /**
     * @brief 掉线入口
     * @return
     */
    virtual int OnDisconnect() { return 0; }

    /**
     * @brief 重连入口
     * @return
     */
    virtual int OnReconnect() { return 0; }

    ////////////////////////////////// 每日零点 每周一零点 刷新接口 ///////////////////////////////////
    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    virtual int DailyZeroTick() { return 0; }

    /**
     * @brief 每日4/6点 刷新接口
     * @return
     */
    virtual int DailyOtherTick() { return 0; }

    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    virtual int WeekZeroTick() { return 0; }

    /**
     * @brief 每月刷新接口
     * @return
     */
    virtual int MonthZeroTick() { return 0; }

public:
    /**
     * @brief update
     */
    virtual int Tick() { return 0; }

public:
    /**
     * @brief 注册要处理的消息
     * @return
     */
    virtual int RegisterMessage();

public:
    /**
     * @brief 处理客户端消息
     * @param msgId
     * @param packet
     * @return
     */
    virtual int OnHandleClientMessage(uint32_t msgId, NFDataPackage& packet);

    /**
     * @brief 处理来自服务器的信息
     * @param msgId
     * @param packet
     * @return
     */
    virtual int OnHandleServerMessage(uint32_t msgId, NFDataPackage& packet);

public:
    /**
     * @brief
     * @param msgId
     * @param createCo
     * @return
     */
    virtual int RegisterClientMessage(uint32_t msgId, bool createCo = false);

    /**
     * @brief
     * @param msgId
     * @param createCo
     * @return
     */
    virtual int RegisterServerMessage(uint32_t msgId, bool createCo = false);

public:
    //部件类型
    uint32_t GetPartType() const { return m_partType; }
    void SetPartType(uint32_t partType) { m_partType = partType; }

    NFSnsRoleDetail* GetRoleDetail();
    const NFSnsRoleDetail* GetRoleDetail() const;


    void SetNeedSave() { MarkDirty(); }

protected:
    uint64_t m_roleId;
    NFObjPtr<NFSnsRoleDetail> m_pRoleDetail;
    uint32_t m_partType;
};
